package com.xaicode.template.gendata.mall.model;

import com.xaicode.template.gendata.mall.common.RandomNum;
import com.xaicode.template.gendata.mall.common.RandomOptionGroup;
import com.xaicode.template.gendata.mall.config.AppConfig;
import com.xaicode.template.gendata.mall.enums.DisplayType;
import com.xaicode.template.gendata.mall.enums.ItemType;
import com.xaicode.template.gendata.mall.enums.PageId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2022/5/24 0024 21:56
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppDisplay {

    ItemType item_type;
    String item;

    DisplayType display_type;
    Integer order;
    Integer pos_id;

    public static List<AppDisplay> buildList(AppPage appPage) {
        List<AppDisplay> displayList = new ArrayList<>();

        if (appPage.page_id == PageId.home || appPage.page_id == PageId.discovery
                || appPage.page_id == PageId.category) {

            int displayCount = RandomNum.getRandInt(1, AppConfig.max_activity_count);
            int pos_id = RandomNum.getRandInt(1, AppConfig.max_pos_id);
            for (int i = 1; i <= displayCount; i++) {
                int actId = RandomNum.getRandInt(1, AppConfig.max_activity_count);
                AppDisplay appDisplay = new AppDisplay(ItemType.activity_id, actId + "", DisplayType.activity, i, pos_id);
                displayList.add(appDisplay);
            }
        }

        if (appPage.page_id == PageId.good_detail || appPage.page_id == PageId.home
                || appPage.page_id == PageId.category || appPage.page_id == PageId.activity
                || appPage.page_id == PageId.good_spec || appPage.page_id == PageId.good_list
                || appPage.page_id == PageId.discovery) {

            int displayCount = RandomNum.getRandInt(AppConfig.min_display_count, AppConfig.max_display_count);
            int activityCount = displayList.size();
            for (int i = 1 + activityCount; i <= displayCount + activityCount; i++) {
                int skuId = RandomNum.getRandInt(1, AppConfig.max_sku_id);
                int pos_id = RandomNum.getRandInt(1, AppConfig.max_pos_id);

                RandomOptionGroup<DisplayType> dispTypeGroup = RandomOptionGroup.builder()
                        .add(DisplayType.promotion, 30)
                        .add(DisplayType.query, 60)
                        .add(DisplayType.recommend, 10).build();
                DisplayType displayType = (DisplayType) dispTypeGroup.getValue();

                AppDisplay appDisplay = new AppDisplay(ItemType.sku_id, skuId + "", displayType, i, pos_id);
                displayList.add(appDisplay);
            }
        }

        return displayList;
    }

}
